package com.kwok.rbac.application.service.impl;

import com.kwok.rbac.application.entity.SystemUser;
import com.kwok.rbac.application.entity.SystemUserToken;
import com.kwok.rbac.application.service.TokenService;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class TokenServiceImpl implements TokenService {

    //Token的过期时间为30分钟
    private Long tokenExpireTime = 30 * 60 * 1000L;

    @Override
    public SystemUserToken createToken(SystemUser systemUser) {
        //创建一个Token
        SystemUserToken systemUserToken = new SystemUserToken();

        //设置Token的值
        systemUserToken.setUserId(systemUser.getUserId());
        systemUserToken.setUsername(systemUser.getUsername());
        Date createTime = new Date();
        systemUserToken.setCreateTime(createTime);
        systemUserToken.setExpireTime(new Date(createTime.getTime() + tokenExpireTime));

        //返回用户的Token
        return systemUserToken;
    }

}
